home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2823 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: mail2news.demon.co.uk!chrism.demon.co.uk
  2. From: Chris Marriott <chris@chrism.demon.co.uk>
  3. Newsgroups: comp.os.ms-windows.programmer.graphics,comp.lang.c++
  4. Subject: Re: Saving a DIB to a file
  5. Date: Fri, 19 Jan 96 19:12:08 GMT
  6. Organization: None
  7. Message-ID: <822078728snz@chrism.demon.co.uk>
  8. References: <NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu>
  9. Reply-To: chris@chrism.demon.co.uk
  10. X-NNTP-Posting-Host: chrism.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.30
  12. X-Mail2News-Path: chrism.demon.co.uk
  13.  
  14. In article <NEWTNews.822065811.24940.finkcr1@ptu-crf-pc.jhuapl.edu>
  15.            finkcr1@ptu-crf-pc.jhuapl.edu  writes:
  16.  
  17. >
  18. >I'm using VC++ 1.5 and have successfully saved the image I drew in an MDI 
  19. >child window to a file as a DIB.  I used as a model the code in the MS example 
  20. >program DIBVIEW.  The problem is that the bitmap I've saved to the file shows 
  21. >up as a monochrome bitmap; the colors displayed in the window do not show up. 
  22. >Here is the code I used to copy the bitmap to a memory DC:
  23. >
  24. >        memDC.CreateCompatibleDC(GetDC())
  25. >                     .
  26. >                     .  
  27. >        bm.CreateCompatibleBitmap(&memDC,rect.Width(),rect.Height());
  28. >                     .
  29. >                     .          
  30. >       oldbm = memDC.SelectObject(&bm);
  31. >       memDC.BitBlt(0, 0, rect.Width(),rect.Height(), GetDC(), 0, 0, SRCCOPY); 
  32. >
  33. >
  34. >When I do a GetObject on the bitmap, it says it has 1 bit per pixel.  I'm 
  35. >confused. I don't completely understand the intricacies of palettes, etc.. The 
  36.  
  37. The problem here is your "CreateCompatibleBitmap" call. You need to create
  38. a bitmap that's compatible with the SCREEN dc, not the MEMORY one.
  39.  
  40. Change your code to say:
  41.  
  42.     CDC *pDC = GetDC();
  43.     memDC.CreateCompatibleDC(pDC);
  44.     bm.CreateCompatibleBitmap( pDC, ..... );
  45.  
  46. and it will work fine.
  47.  
  48. Chris
  49.  
  50.  
  51. -- 
  52. --------------------------------------------------------------------------
  53.  Chris Marriott, Warrington, UK      | Author of SkyMap v3 award-winning 
  54.  chris@chrism.demon.co.uk            | shareware Win31/Win95 planetarium.
  55.             For full info, see http://www.execpc.com/~skymap  
  56.       Author member of Association of Shareware Professionals (ASP) 
  57. -------------------------------------------------------------------------- 
  58.  
  59.